.set LOCALID_ATTENDANT_SINGLES, 1
.set LOCALID_ATTENDANT_DOUBLES, 7
.set LOCALID_ATTENDANT_MULTIS, 8
.set LOCALID_ATTENDANT_LINK_MULTIS, 9

@ Note: LOCALID_BATTLE_TOWER_LOBBY_REPORTER is a local id for this map used elsewhere. It's defined in event_objects.h

BattleFrontier_BattleTowerLobby_MapScripts::
	map_script MAP_SCRIPT_ON_RESUME, BattleFrontier_BattleTowerLobby_OnResume
	map_script MAP_SCRIPT_ON_TRANSITION, BattleFrontier_BattleTowerLobby_OnTransition
	map_script MAP_SCRIPT_ON_FRAME_TABLE, BattleFrontier_BattleTowerLobby_OnFrame
	map_script MAP_SCRIPT_ON_WARP_INTO_MAP_TABLE, BattleFrontier_BattleTowerLobby_OnWarp
	.byte 0

BattleFrontier_BattleTowerLobby_OnResume:
	special TryHideBattleTowerReporter
	end

BattleFrontier_BattleTowerLobby_OnTransition:
	call BattleFrontier_BattleTowerLobby_EventScript_ShowOrHideReporter
	apprentice_shouldcheckgone
	compare VAR_0x8004, FALSE  @ Always TRUE here
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_ShowApprentice
	goto_if_set FLAG_DAILY_APPRENTICE_LEAVES, BattleFrontier_BattleTowerLobby_EventScript_HideApprentice
BattleFrontier_BattleTowerLobby_EventScript_ShowApprentice::
	clearflag FLAG_HIDE_APPRENTICE
	apprentice_setgfx
BattleFrontier_BattleTowerLobby_EventScript_EndShowOrHideApprentice::
	end

BattleFrontier_BattleTowerLobby_EventScript_HideApprentice::
	setflag FLAG_HIDE_APPRENTICE
	goto BattleFrontier_BattleTowerLobby_EventScript_EndShowOrHideApprentice

BattleFrontier_BattleTowerLobby_OnWarp:
	map_script_2 VAR_TEMP_1, 0, BattleFrontier_BattleTowerLobby_EventScript_PlayerFaceNorth
	.2byte 0

BattleFrontier_BattleTowerLobby_EventScript_PlayerFaceNorth::
	setvar VAR_TEMP_1, 1
	turnobject OBJ_EVENT_ID_PLAYER, DIR_NORTH
	end

BattleFrontier_BattleTowerLobby_OnFrame:
	map_script_2 VAR_TEMP_0, 0, BattleFrontier_BattleTowerLobby_EventScript_GetChallengeStatus
	map_script_2 VAR_TEMP_0, CHALLENGE_STATUS_SAVING, BattleFrontier_BattleTowerLobby_EventScript_QuitWithoutSaving
	map_script_2 VAR_TEMP_0, CHALLENGE_STATUS_PAUSED, BattleFrontier_BattleTowerLobby_EventScript_ResumeChallenge
	map_script_2 VAR_TEMP_0, CHALLENGE_STATUS_WON, BattleFrontier_BattleTowerLobby_EventScript_WonChallenge
	map_script_2 VAR_TEMP_0, CHALLENGE_STATUS_LOST, BattleFrontier_BattleTowerLobby_EventScript_LostChallenge
	.2byte 0

BattleFrontier_BattleTowerLobby_EventScript_GetChallengeStatus::
	frontier_getstatus
	end

BattleFrontier_BattleTowerLobby_EventScript_QuitWithoutSaving::
	lock
	faceplayer
	msgbox BattleFrontier_BattleTowerLobby_Text_DidntSaveBeforeQuitting, MSGBOX_DEFAULT
	closemessage
	tower_set TOWER_DATA_WIN_STREAK, 0
	tower_set TOWER_DATA_WIN_STREAK_ACTIVE, FALSE
	frontier_set FRONTIER_DATA_CHALLENGE_STATUS, 0
	setvar VAR_TEMP_0, 255
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_WonChallenge::
	lock
	faceplayer
	frontier_isbrain
	compare VAR_RESULT, TRUE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_DefeatedMaiden
	message BattleFrontier_BattleTowerLobby_Text_CongratsBeatenSeven
	waitmessage
	goto BattleFrontier_BattleTowerLobby_EventScript_GiveRibbons

BattleFrontier_BattleTowerLobby_EventScript_DefeatedMaiden::
	msgbox BattleFrontier_BattleTowerLobby_Text_CongratsDefeatedMaiden, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_GiveRibbons::
	tower_giveribbons
	compare VAR_RESULT, FALSE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_GiveBattlePoints
	message BattleFrontier_BattleTowerLobby_Text_HereAreSomeRibbons
	waitmessage
	playfanfare MUS_OBTAIN_ITEM
	waitfanfare
	msgbox BattleFrontier_BattleTowerLobby_Text_PutRibbonOnMons, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_GiveBattlePoints::
	msgbox BattleFrontier_BattleTowerLobby_Text_AwardYouTheseBattlePoints, MSGBOX_DEFAULT
	frontier_givepoints
	msgbox BattleFrontier_Text_ObtainedXBattlePoints, MSGBOX_GETPOINTS
	call BattleFrontier_BattleTowerLobby_EventScript_AskSaveBattle
	tower_get TOWER_DATA_WIN_STREAK
	compare VAR_RESULT, 49
	goto_if_ne BattleFrontier_BattleTowerLobby_EventScript_LookForwardToChallenge
	msgbox BattleFrontier_BattleTowerLobby_Text_AboutToFace50thTrainer, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_LookForwardToChallenge::
	msgbox BattleFrontier_BattleTowerLobby_Text_LookForwardToAnotherChallenge, MSGBOX_DEFAULT
	closemessage
	setvar VAR_TEMP_0, 255
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_LostChallenge::
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_MULTIS
	goto_if_ne BattleFrontier_BattleTowerLobby_EventScript_CancelWinStreak
	goto_if_set FLAG_CHOSEN_MULTI_BATTLE_NPC_PARTNER, BattleFrontier_BattleTowerLobby_EventScript_CancelWinStreak
	tower_get TOWER_DATA_WIN_STREAK
	compare VAR_RESULT, 0
	goto_if_ne BattleFrontier_BattleTowerLobby_EventScript_LostThanksForPlaying
BattleFrontier_BattleTowerLobby_EventScript_CancelWinStreak::
	tower_set TOWER_DATA_WIN_STREAK_ACTIVE, FALSE
BattleFrontier_BattleTowerLobby_EventScript_LostThanksForPlaying::
	lock
	faceplayer
	message BattleFrontier_BattleTowerLobby_Text_ThankYouForPlaying
	waitmessage
	call BattleFrontier_BattleTowerLobby_EventScript_AskSaveBattle
	msgbox BattleFrontier_BattleTowerLobby_Text_LookForwardToAnotherChallenge, MSGBOX_DEFAULT
	closemessage
	setvar VAR_TEMP_0, 255
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_AskSaveBattle::
	message BattleFrontier_BattleTowerLobby_Text_RecordWillBeSaved
	waitmessage
	frontier_checkairshow
	special LoadPlayerParty
	special HealPlayerParty
	tower_save 0
	playse SE_SAVE
	waitse
	call BattleFrontier_EventScript_GetCantRecordBattle
	compare VAR_RESULT, TRUE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_EndSaveBattle
	message BattleFrontier_BattleTowerLobby_Text_RecordLastMatch
	waitmessage
	multichoicedefault 20, 8, MULTI_YESNO, 1, FALSE
	switch VAR_RESULT
	case 1, BattleFrontier_BattleTowerLobby_EventScript_EndSaveBattle
	case 0, BattleFrontier_EventScript_SaveBattle
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_EndSaveBattle

BattleFrontier_EventScript_SaveBattle::
	frontier_savebattle
	compare VAR_RESULT, FALSE
	goto_if_eq BattleFrontier_EventScript_BattleSaveFailed
	playse SE_SAVE
	msgbox BattleFrontier_BattleTowerLobby_Text_BattleRecordedOnPass, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_EndSaveBattle

BattleFrontier_EventScript_BattleSaveFailed::
	msgbox BattleFrontier_BattleTowerBattleRoom_Text_RecordCouldntBeSaved, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_EndSaveBattle::
	return

BattleFrontier_EventScript_GetCantRecordBattle::
	frontier_get FRONTIER_DATA_RECORD_DISABLED
	return

BattleFrontier_BattleTowerLobby_EventScript_ResumeChallenge::
	lock
	faceplayer
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_SINGLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_SetBravoTrainerOn
	message BattleFrontier_BattleTowerLobby_Text_WeveBeenWaitingForYou
	waitmessage
	message BattleFrontier_BattleTowerLobby_Text_ProgressWillBeSaved
	waitmessage
	tower_save CHALLENGE_STATUS_SAVING
	playse SE_SAVE
	waitse
	frontier_set FRONTIER_DATA_PAUSED, FALSE
	goto BattleFrontier_BattleTowerLobby_EventScript_EnterElevator
	end

BattleFrontier_BattleTowerLobby_EventScript_SetBravoTrainerOn::
	setvar VAR_BRAVO_TRAINER_BATTLE_TOWER_ON, TRUE
	return

BattleFrontier_BattleTowerLobby_EventScript_SinglesAttendant::
	lock
	faceplayer
	setvar VAR_FRONTIER_FACILITY, FRONTIER_FACILITY_TOWER
	special SavePlayerParty
	msgbox BattleFrontier_BattleTowerLobby_Text_WelcomSingleBattle, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_AskEnterSinglesChallenge::
	message BattleFrontier_BattleTowerLobby_Text_TakeSinglesChallenge
	waitmessage
	multichoice 17, 6, MULTI_CHALLENGEINFO, FALSE
	switch VAR_RESULT
	case 0, BattleFrontier_BattleTowerLobby_EventScript_TryEnterSinglesChallenge
	case 1, BattleFrontier_BattleTowerLobby_EventScript_ExplainSinglesChallenge
	case 2, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_TryEnterSinglesChallenge::
	setvar VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_SINGLES
	message BattleFrontier_BattleTowerLobby_Text_WhichLevelMode
	waitmessage
	multichoice 17, 6, MULTI_LEVEL_MODE, FALSE
	switch VAR_RESULT
	case FRONTIER_LVL_TENT, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	frontier_checkineligible
	compare VAR_0x8004, TRUE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMons
	frontier_set FRONTIER_DATA_LVL_MODE, VAR_RESULT
	msgbox BattleFrontier_BattleTowerLobby_Text_SelectThreeMons, MSGBOX_DEFAULT
	fadescreen FADE_TO_BLACK
	call BattleFrontier_EventScript_GetLvlMode
	copyvar VAR_0x8004, VAR_RESULT
	setvar VAR_0x8005, FRONTIER_PARTY_SIZE
	special ChoosePartyForBattleFrontier
	waitstate
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	msgbox BattleFrontier_BattleTowerLobby_Text_OkayToSaveBeforeEntering, MSGBOX_YESNO
	switch VAR_RESULT
	case NO, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	case YES, BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeSinglesChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeSinglesChallenge::
	frontier_set FRONTIER_DATA_SELECTED_MON_ORDER
	setvar VAR_TEMP_0, 0
	tower_init
	tower_set TOWER_DATA_WIN_STREAK_ACTIVE, TRUE
	frontier_set FRONTIER_DATA_PAUSED, FALSE
	special LoadPlayerParty
	closemessage
	delay 2
	call Common_EventScript_SaveGame
	setvar VAR_TEMP_0, 255
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_CancelChallengeSaveFailed
	incrementgamestat GAME_STAT_ENTERED_BATTLE_TOWER
	setvar VAR_BRAVO_TRAINER_BATTLE_TOWER_ON, TRUE
	goto BattleFrontier_BattleTowerLobby_EventScript_EnterElevator
	end

BattleFrontier_BattleTowerLobby_EventScript_ExplainSinglesChallenge::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainSinglesChallenge, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_AskEnterSinglesChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_DoublesAttendant::
	lock
	faceplayer
	setvar VAR_FRONTIER_FACILITY, FRONTIER_FACILITY_TOWER
	special SavePlayerParty
	msgbox BattleFrontier_BattleTowerLobby_Text_WelcomeDoubleBattle, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_AskEnterDoublesChallenge::
	message BattleFrontier_BattleTowerLobby_Text_TakeDoublesChallenge
	waitmessage
	multichoice 17, 6, MULTI_CHALLENGEINFO, FALSE
	switch VAR_RESULT
	case 0, BattleFrontier_BattleTowerLobby_EventScript_TryEnterDoublesChallenge
	case 1, BattleFrontier_BattleTowerLobby_EventScript_ExplainDoublesChallenge
	case 2, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_TryEnterDoublesChallenge::
	setvar VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_DOUBLES
	message BattleFrontier_BattleTowerLobby_Text_WhichLevelMode
	waitmessage
	multichoice 17, 6, MULTI_LEVEL_MODE, FALSE
	switch VAR_RESULT
	case FRONTIER_LVL_TENT, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	frontier_checkineligible
	compare VAR_0x8004, TRUE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMons
	frontier_set FRONTIER_DATA_LVL_MODE, VAR_RESULT
	msgbox BattleFrontier_BattleTowerLobby_Text_PleaseSelectFourMons, MSGBOX_DEFAULT
	fadescreen FADE_TO_BLACK
	call BattleFrontier_EventScript_GetLvlMode
	copyvar VAR_0x8004, VAR_RESULT
	setvar VAR_0x8005, FRONTIER_DOUBLES_PARTY_SIZE
	special ChoosePartyForBattleFrontier
	waitstate
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	msgbox BattleFrontier_BattleTowerLobby_Text_OkayToSaveBeforeEntering, MSGBOX_YESNO
	switch VAR_RESULT
	case NO, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	case YES, BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeDoublesChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeDoublesChallenge::
	frontier_set FRONTIER_DATA_SELECTED_MON_ORDER
	setvar VAR_TEMP_0, 0
	tower_init
	tower_set TOWER_DATA_WIN_STREAK_ACTIVE, TRUE
	frontier_set FRONTIER_DATA_PAUSED, FALSE
	special LoadPlayerParty
	closemessage
	delay 2
	call Common_EventScript_SaveGame
	setvar VAR_TEMP_0, 255
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_CancelChallengeSaveFailed
	incrementgamestat GAME_STAT_ENTERED_BATTLE_TOWER
	setvar VAR_BRAVO_TRAINER_BATTLE_TOWER_ON, FALSE
	goto BattleFrontier_BattleTowerLobby_EventScript_EnterElevator
	end

BattleFrontier_BattleTowerLobby_EventScript_ExplainDoublesChallenge::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainDoublesChallenge, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_AskEnterDoublesChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_MultisAttendant::
	lock
	faceplayer
	setvar VAR_FRONTIER_FACILITY, FRONTIER_FACILITY_TOWER
	clearflag FLAG_CHOSEN_MULTI_BATTLE_NPC_PARTNER
	special SavePlayerParty
	msgbox BattleFrontier_BattleTowerLobby_Text_WelcomeMultiBattle, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_AskEnterMultisChallenge::
	message BattleFrontier_BattleTowerLobby_Text_TakeMultisChallenge
	waitmessage
	multichoice 17, 6, MULTI_CHALLENGEINFO, FALSE
	switch VAR_RESULT
	case 0, BattleFrontier_BattleTowerLobby_EventScript_TryEnterMultisChallenge
	case 1, BattleFrontier_BattleTowerLobby_EventScript_ExplainMultisChallenge
	case 2, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_TryEnterMultisChallenge::
	setvar VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_MULTIS
	message BattleFrontier_BattleTowerLobby_Text_WhichLevelMode
	waitmessage
	multichoice 17, 6, MULTI_LEVEL_MODE, FALSE
	switch VAR_RESULT
	case FRONTIER_LVL_TENT, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	frontier_checkineligible
	compare VAR_0x8004, TRUE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMons
	frontier_set FRONTIER_DATA_LVL_MODE, VAR_RESULT
	msgbox BattleFrontier_BattleTowerLobby_Text_PleaseSelectTwoMons, MSGBOX_DEFAULT
	fadescreen FADE_TO_BLACK
	call BattleFrontier_EventScript_GetLvlMode
	copyvar VAR_0x8004, VAR_RESULT
	setvar VAR_0x8005, FRONTIER_MULTI_PARTY_SIZE
	special ChoosePartyForBattleFrontier
	waitstate
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	msgbox BattleFrontier_BattleTowerLobby_Text_OkayToSaveBeforeEntering, MSGBOX_YESNO
	switch VAR_RESULT
	case NO, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	case YES, BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeMultisChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeMultisChallenge::
	frontier_set FRONTIER_DATA_SELECTED_MON_ORDER
	setvar VAR_TEMP_0, 0
	tower_init
	tower_set TOWER_DATA_WIN_STREAK_ACTIVE, TRUE
	frontier_set FRONTIER_DATA_PAUSED, FALSE
	special LoadPlayerParty
	closemessage
	delay 2
	call Common_EventScript_SaveGame
	setvar VAR_TEMP_0, 255
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_CancelChallengeSaveFailed
	incrementgamestat GAME_STAT_ENTERED_BATTLE_TOWER
	setvar VAR_BRAVO_TRAINER_BATTLE_TOWER_ON, FALSE
	goto BattleFrontier_BattleTowerLobby_EventScript_EnterElevator
	end

BattleFrontier_BattleTowerLobby_EventScript_ExplainMultisChallenge::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainMultisChallenge, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_AskEnterMultisChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_LinkMultisAttendant::
	lock
	faceplayer
	setvar VAR_FRONTIER_FACILITY, FRONTIER_FACILITY_TOWER
	special SavePlayerParty
	msgbox BattleFrontier_BattleTowerLobby_Text_WelcomeLinkMultiBattle, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_AskEnterLinkMultisChallenge::
	message BattleFrontier_BattleTowerLobby_Text_TakeLinkMultisChallenge
	waitmessage
	multichoice 17, 6, MULTI_CHALLENGEINFO, FALSE
	switch VAR_RESULT
	case 0, BattleFrontier_BattleTowerLobby_EventScript_TryEnterLinkMultisChallenge
	case 1, BattleFrontier_BattleTowerLobby_EventScript_ExplainLinkMultisChallenge
	case 2, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_TryEnterLinkMultisChallenge::
	setvar VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_LINK_MULTIS
	message BattleFrontier_BattleTowerLobby_Text_WhichLevelMode
	waitmessage
	multichoice 17, 6, MULTI_LEVEL_MODE, FALSE
	switch VAR_RESULT
	case FRONTIER_LVL_TENT, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	frontier_checkineligible
	compare VAR_0x8004, TRUE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMons
	frontier_set FRONTIER_DATA_LVL_MODE, VAR_RESULT
	msgbox BattleFrontier_BattleTowerLobby_Text_PleaseSelectTwoMons2, MSGBOX_DEFAULT
	fadescreen FADE_TO_BLACK
	call BattleFrontier_EventScript_GetLvlMode
	copyvar VAR_0x8004, VAR_RESULT
	setvar VAR_0x8005, FRONTIER_MULTI_PARTY_SIZE
	special ChoosePartyForBattleFrontier
	waitstate
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	msgbox BattleFrontier_BattleTowerLobby_Text_OkayToSaveBeforeEntering, MSGBOX_YESNO
	switch VAR_RESULT
	case NO, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge
	case YES, BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeLinkMultisChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge

BattleFrontier_BattleTowerLobby_EventScript_SaveBeforeLinkMultisChallenge::
	frontier_set FRONTIER_DATA_SELECTED_MON_ORDER
	setvar VAR_TEMP_0, 0
	tower_init
	tower_set TOWER_DATA_WIN_STREAK_ACTIVE, TRUE
	frontier_set FRONTIER_DATA_PAUSED, FALSE
	special LoadPlayerParty
	closemessage
	delay 2
	tower_save 0
	call Common_EventScript_SaveGame
	setvar VAR_TEMP_0, 255
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_CancelChallengeSaveFailed
	incrementgamestat GAME_STAT_ENTERED_BATTLE_TOWER
	specialvar VAR_RESULT, IsWirelessAdapterConnected
	compare VAR_RESULT, TRUE
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_TryWirelessLink
	goto BattleFrontier_BattleTowerLobby_EventScript_TryCableLink
	end

BattleFrontier_BattleTowerLobby_EventScript_FeelingsMan::
	lock
	faceplayer
	message BattleFrontier_BattleTowerLobby_Text_DescribeFeelingsAboutBattleTower
	waitmessage
	multichoice 16, 4, MULTI_BATTLE_TOWER_FEELINGS, FALSE
	switch VAR_RESULT
	case 0, BattleFrontier_BattleTowerLobby_EventScript_FeelingsBattleNow
	case 1, BattleFrontier_BattleTowerLobby_EventScript_FeelingsIWon
	case 2, BattleFrontier_BattleTowerLobby_EventScript_FeelingsILost
	case 3, BattleFrontier_BattleTowerLobby_EventScript_FeelingsWontTell
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_FeelingsWontTell
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_FeelingsBattleNow::
	msgbox BattleFrontier_BattleTowerLobby_Text_FeelWhatWhenYouBegin, MSGBOX_DEFAULT
	setvar VAR_0x8004, EASY_CHAT_TYPE_BATTLE_START
	call Common_ShowEasyChatScreen
	lock
	faceplayer
	goto BattleFrontier_BattleTowerLobby_EventScript_CheckFeelings
	end

BattleFrontier_BattleTowerLobby_EventScript_FeelingsIWon::
	msgbox BattleFrontier_BattleTowerLobby_Text_FeelWhatWhenYouveWon, MSGBOX_DEFAULT
	setvar VAR_0x8004, EASY_CHAT_TYPE_BATTLE_WON
	call Common_ShowEasyChatScreen
	lock
	faceplayer
	goto BattleFrontier_BattleTowerLobby_EventScript_CheckFeelings
	end

BattleFrontier_BattleTowerLobby_EventScript_FeelingsILost::
	msgbox BattleFrontier_BattleTowerLobby_Text_FeelWhatWhenYouveLost, MSGBOX_DEFAULT
	setvar VAR_0x8004, EASY_CHAT_TYPE_BATTLE_LOST
	call Common_ShowEasyChatScreen
	lock
	faceplayer
	goto BattleFrontier_BattleTowerLobby_EventScript_CheckFeelings
	end

BattleFrontier_BattleTowerLobby_EventScript_FeelingsWontTell::
	msgbox BattleFrontier_BattleTowerLobby_Text_DontThinkMuchAboutIt, MSGBOX_DEFAULT
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_CheckFeelings::
	compare VAR_RESULT, 0
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_CanceledEasyChat
	compare VAR_RESULT, 1
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_SubmittedFeelings
	end

BattleFrontier_BattleTowerLobby_EventScript_CanceledEasyChat::
	msgbox BattleFrontier_BattleTowerLobby_Text_ChangedYourMind, MSGBOX_DEFAULT
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_SubmittedFeelings::
	msgbox BattleFrontier_BattleTowerLobby_Text_ThatsHowYouFeel, MSGBOX_DEFAULT
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_Woman::
	msgbox BattleFrontier_BattleTowerLobby_Text_WinsInRowRecorded, MSGBOX_NPC
	end

BattleFrontier_BattleTowerLobby_EventScript_Boy::
	msgbox BattleFrontier_BattleTowerLobby_Text_CanLeaveUntilLossOrSevenWins, MSGBOX_NPC
	end

BattleFrontier_BattleTowerLobby_EventScript_ShowSinglesResults::
	lockall
	frontier_results FRONTIER_FACILITY_TOWER, FRONTIER_MODE_SINGLES
	waitbuttonpress
	special RemoveRecordsWindow
	releaseall
	end

BattleFrontier_BattleTowerLobby_EventScript_ShowDoublesResults::
	lockall
	frontier_results FRONTIER_FACILITY_TOWER, FRONTIER_MODE_DOUBLES
	waitbuttonpress
	special RemoveRecordsWindow
	releaseall
	end

BattleFrontier_BattleTowerLobby_EventScript_ShowMultisResults::
	lockall
	frontier_results FRONTIER_FACILITY_TOWER, FRONTIER_MODE_MULTIS
	waitbuttonpress
	special RemoveRecordsWindow
	releaseall
	end

BattleFrontier_BattleTowerLobby_EventScript_ShowLinkMultisResults::
	lockall
	frontier_results FRONTIER_FACILITY_TOWER, FRONTIER_MODE_LINK_MULTIS
	waitbuttonpress
	special RemoveRecordsWindow
	releaseall
	end

BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMons::
	switch VAR_RESULT
	case FRONTIER_LVL_50, BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLv50
	case FRONTIER_LVL_OPEN, BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLvOpen

BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLv50::
	switch VAR_FRONTIER_BATTLE_MODE
	case FRONTIER_MODE_SINGLES, BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLv50Singles
	case FRONTIER_MODE_DOUBLES, BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLv50Doubles
	msgbox BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLv50Multis, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_EndCancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLv50Singles::
	msgbox BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLv50Singles, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_EndCancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLv50Doubles::
	msgbox BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLv50Doubles, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_EndCancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLvOpen::
	switch VAR_FRONTIER_BATTLE_MODE
	case FRONTIER_MODE_SINGLES, BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLvOpenSingles
	case FRONTIER_MODE_DOUBLES, BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLvOpenDoubles
	msgbox BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLvOpenMultis, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_EndCancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLvOpenSingles::
	msgbox BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLvOpenSingles, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_EndCancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_NotEnoughValidMonsLvOpenDoubles::
	msgbox BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLvOpenDoubles, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_EndCancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_CancelChallengeSaveFailed::
	frontier_set FRONTIER_DATA_CHALLENGE_STATUS  @ No status provided, so it relies on VAR_0x8006 being 0 already
	goto BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_LoadPartyCancelChallenge::
	special LoadPlayerParty
BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge::
	special CloseLink
	msgbox BattleFrontier_BattleTowerLobby_Text_LookForwardToAnotherChallenge, MSGBOX_DEFAULT
BattleFrontier_BattleTowerLobby_EventScript_EndCancelChallenge::
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_EnterElevator::
	special SavePlayerParty
	setvar VAR_0x8004, FRONTIER_UTIL_FUNC_SET_PARTY_ORDER
	call BattleFrontier_BattleTowerLobby_EventScript_GetPartySize
	special CallFrontierUtilFunc
	setvar VAR_RESULT, 0
BattleFrontier_BattleTowerLobby_EventScript_WaitForLinkOpponentLoad::
	tower_loadlinkopponents
	delay 1
	compare VAR_RESULT, 6
	goto_if_ne BattleFrontier_BattleTowerLobby_EventScript_WaitForLinkOpponentLoad
	call BattleFrontier_BattleTowerLobby_EventScript_ShowYouToBattleRoom
	clearflag FLAG_CANCEL_BATTLE_ROOM_CHALLENGE
	warp MAP_BATTLE_FRONTIER_BATTLE_TOWER_ELEVATOR, 255, 1, 6
	setvar VAR_TEMP_0, 0
	waitstate
	end

BattleFrontier_BattleTowerLobby_EventScript_ShowYouToBattleRoom::
	call BattleFrontier_BattleTowerLobby_EventScript_BufferModeText
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_LINK_MULTIS
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_ShowYouToLinkMultiBattleRoom
	msgbox BattleFrontier_BattleTowerLobby_Text_ShowYouToBattleRoom, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_WalkToElevator

BattleFrontier_BattleTowerLobby_EventScript_ShowYouToLinkMultiBattleRoom::
	messageautoscroll BattleFrontier_BattleTowerLobby_Text_ShowYouToBattleRoom
	waitmessage
	delay 48
BattleFrontier_BattleTowerLobby_EventScript_WalkToElevator::
	closemessage
	call BattleFrontier_BattleTowerLobby_EventScript_SetAttendantTalkedTo
	call BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoord
	applymovement VAR_LAST_TALKED, BattleFrontier_BattleTowerLobby_Movement_WalkToElevator
	applymovement OBJ_EVENT_ID_PLAYER, BattleFrontier_BattleTowerLobby_Movement_WalkToElevator
	waitmovement 0
	opendoor VAR_0x8004, 1
	waitdooranim
	applymovement VAR_LAST_TALKED, BattleFrontier_BattleTowerLobby_Movement_AttendantEnterElevator
	applymovement OBJ_EVENT_ID_PLAYER, BattleFrontier_BattleTowerLobby_Movement_PlayerEnterElevator
	waitmovement 0
	closedoor VAR_0x8004, 1
	waitdooranim
	return

BattleFrontier_BattleTowerLobby_Movement_WalkToElevator:
	walk_up
	walk_up
	walk_up
	step_end

BattleFrontier_BattleTowerLobby_Movement_AttendantEnterElevator:
	walk_up
	set_invisible
	step_end

BattleFrontier_BattleTowerLobby_Movement_PlayerEnterElevator:
	walk_up
	walk_up
	set_invisible
	step_end

@ Unused
BattleFrontier_BattleTowerLobby_Movement_UnusedEnterElevator:
	walk_fast_up
	walk_fast_up
	walk_fast_up
	walk_fast_up
	walk_fast_up
	set_invisible
	step_end

BattleFrontier_BattleTowerLobby_EventScript_BufferModeText::
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_SINGLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_BufferTextSingle
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_DOUBLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_BufferTextDouble
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_BufferTextMulti
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_LINK_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_BufferTextLinkMulti
	return

BattleFrontier_BattleTowerLobby_EventScript_BufferTextSingle::
	bufferstdstring 0, STDSTRING_SINGLE
	return

BattleFrontier_BattleTowerLobby_EventScript_BufferTextDouble::
	bufferstdstring 0, STDSTRING_DOUBLE
	return

BattleFrontier_BattleTowerLobby_EventScript_BufferTextMulti::
	bufferstdstring 0, STDSTRING_MULTI
	return

BattleFrontier_BattleTowerLobby_EventScript_BufferTextLinkMulti::
	bufferstdstring 0, STDSTRING_MULTI_LINK
	return

BattleFrontier_BattleTowerLobby_EventScript_SetAttendantTalkedTo::
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_SINGLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_TalkedToSinglesAttendant
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_DOUBLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_TalkedToDoublesAttendant
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_TalkedToMultisAttendant
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_LINK_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_TalkedToLinkMultisAttendant
	return

BattleFrontier_BattleTowerLobby_EventScript_TalkedToSinglesAttendant::
	setvar VAR_LAST_TALKED, LOCALID_ATTENDANT_SINGLES
	return

BattleFrontier_BattleTowerLobby_EventScript_TalkedToDoublesAttendant::
	setvar VAR_LAST_TALKED, LOCALID_ATTENDANT_DOUBLES
	return

BattleFrontier_BattleTowerLobby_EventScript_TalkedToMultisAttendant::
	setvar VAR_LAST_TALKED, LOCALID_ATTENDANT_MULTIS
	return

BattleFrontier_BattleTowerLobby_EventScript_TalkedToLinkMultisAttendant::
	setvar VAR_LAST_TALKED, LOCALID_ATTENDANT_LINK_MULTIS
	return

BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoord::
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_SINGLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordSingles
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_DOUBLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordDoubles
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordMultis
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_LINK_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordLinkMultis
	return

BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordSingles::
	setvar VAR_0x8004, 6
	return

BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordDoubles::
	setvar VAR_0x8004, 10
	return

BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordMultis::
	setvar VAR_0x8004, 14
	return

BattleFrontier_BattleTowerLobby_EventScript_GetDoorXCoordLinkMultis::
	setvar VAR_0x8004, 18
	return

BattleFrontier_BattleTowerLobby_EventScript_GetPartySize::
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_SINGLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetSinglesPartySize
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_DOUBLES
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetDoublesPartySize
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetMultisPartySize
	compare VAR_FRONTIER_BATTLE_MODE, FRONTIER_MODE_LINK_MULTIS
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_GetLinkMultisPartySize
	return

BattleFrontier_BattleTowerLobby_EventScript_GetSinglesPartySize::
	setvar VAR_0x8005, FRONTIER_PARTY_SIZE
	return

BattleFrontier_BattleTowerLobby_EventScript_GetDoublesPartySize::
	setvar VAR_0x8005, FRONTIER_DOUBLES_PARTY_SIZE
	return

BattleFrontier_BattleTowerLobby_EventScript_GetMultisPartySize::
	setvar VAR_0x8005, FRONTIER_MULTI_PARTY_SIZE
	return

BattleFrontier_BattleTowerLobby_EventScript_GetLinkMultisPartySize::
	setvar VAR_0x8005, FRONTIER_MULTI_PARTY_SIZE
	return

BattleFrontier_EventScript_GetLvlMode::
	frontier_get FRONTIER_DATA_LVL_MODE
	return

BattleFrontier_BattleTowerLobby_EventScript_TryCableLink::
	setvar VAR_0x8004, USING_BATTLE_TOWER
	message gText_PleaseWaitForLink
	waitmessage
	setvar VAR_0x8005, 0
	special TryBattleLinkup
	waitstate
	compare VAR_RESULT, LINKUP_SUCCESS
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_CableLinkSuccessful
	compare VAR_RESULT, LINKUP_SOMEONE_NOT_READY
	goto_if_eq CableClub_EventScript_AbortLinkSomeoneNotReady
	compare VAR_RESULT, LINKUP_DIFF_SELECTIONS
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_AbortLinkDifferentSelections
	compare VAR_RESULT, LINKUP_WRONG_NUM_PLAYERS
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_AbortLinkIncorrectNumberOfPlayers
	compare VAR_RESULT, LINKUP_FAILED
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	compare VAR_RESULT, LINKUP_CONNECTION_ERROR
	goto_if_eq CableClub_EventScript_AbortLinkConnectionError
	compare VAR_RESULT, LINKUP_FAILED_BATTLE_TOWER
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_AbortLink
	end

BattleFrontier_BattleTowerLobby_EventScript_AbortLinkDifferentSelections::
	special CloseLink
	compare VAR_0x8005, 3
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_FriendDifferentSelection
	msgbox Text_PlayersMadeDifferentSelections, MSGBOX_DEFAULT
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_FriendDifferentSelection::
	msgbox BattleFrontier_BattleTowerLobby_Text_FriendChoseDifferentLvlMode, MSGBOX_DEFAULT
	msgbox BattleFrontier_BattleTowerLobby_Text_ChooseDifferentMonsMatchLvlMode, MSGBOX_DEFAULT
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_AbortLinkIncorrectNumberOfPlayers::
	msgbox BattleFrontier_BattleTowerLobby_Text_LinkMultiOnlyForTwoPlayers, MSGBOX_DEFAULT
	special CloseLink
	msgbox CableClub_Text_IncorrectNumberOfParticipants, MSGBOX_DEFAULT
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_AbortLink::
	special CloseLink
	compare VAR_0x8005, 0
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_FriendChoseDifferentLvlMode
	compare VAR_0x8005, 1
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_FriendAlsoSelectedMon
	compare VAR_0x8005, 2
	call_if_eq BattleFrontier_BattleTowerLobby_EventScript_FriendAlsoSelectedMons
	msgbox BattleFrontier_BattleTowerLobby_Text_ChooseDifferentMonsMatchLvlMode, MSGBOX_DEFAULT
	release
	end

BattleFrontier_BattleTowerLobby_EventScript_FriendChoseDifferentLvlMode::
	msgbox BattleFrontier_BattleTowerLobby_Text_FriendChoseDifferentLvlMode, MSGBOX_DEFAULT
	return

BattleFrontier_BattleTowerLobby_EventScript_FriendAlsoSelectedMon::
	msgbox BattleFrontier_BattleTowerLobby_Text_FriendAlsoSelectedMon, MSGBOX_DEFAULT
	return

BattleFrontier_BattleTowerLobby_EventScript_FriendAlsoSelectedMons::
	msgbox BattleFrontier_BattleTowerLobby_Text_FriendAlsoSelectedMons, MSGBOX_DEFAULT
	return

BattleFrontier_BattleTowerLobby_EventScript_CableLinkSuccessful::
	incrementgamestat GAME_STAT_ENTERED_BATTLE_TOWER
	setvar VAR_BRAVO_TRAINER_BATTLE_TOWER_ON, FALSE
	message BattleFrontier_BattleTowerLobby_Text_SaveGameBeforeShowingIn
	waitmessage
	tower_save CHALLENGE_STATUS_SAVING
	special SaveForBattleTowerLink
	waitstate
	playse SE_SAVE
	waitse
	special TrySetBattleTowerLinkType
	goto BattleFrontier_BattleTowerLobby_EventScript_EnterElevator
	end

BattleFrontier_BattleTowerLobby_EventScript_ExplainLinkMultisChallenge::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainLinkMultisChallenge, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_AskEnterLinkMultisChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_TryWirelessLink::
	setvar VAR_0x8004, LINK_GROUP_BATTLE_TOWER
	goto BattleFrontier_BattleTowerLobby_EventScript_ChooseLeader
	end

BattleFrontier_BattleTowerLobby_EventScript_ChooseLeader::
	message CableClub_Text_ChooseGroupLeaderOfTwo
	waitmessage
	multichoice 16, 6, MULTI_LINK_LEADER, FALSE
	switch VAR_RESULT
	case 0, BattleFrontier_BattleTowerLobby_EventScript_TryJoinGroup
	case 1, BattleFrontier_BattleTowerLobby_EventScript_TryBecomeLeader
	case 2, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_CancelChallenge
	end

BattleFrontier_BattleTowerLobby_EventScript_TryBecomeLeader::
	call CableClub_EventScript_TryBecomeLinkLeader
	compare VAR_RESULT, LINKUP_SUCCESS
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_WirelessLinkSuccessful
	compare VAR_RESULT, LINKUP_FAILED
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_ChooseLeader
	compare VAR_RESULT, LINKUP_RETRY_ROLE_ASSIGN
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_TryBecomeLeader
	compare VAR_RESULT, LINKUP_FAILED_BATTLE_TOWER
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_AbortLink
	release
	return

BattleFrontier_BattleTowerLobby_EventScript_TryJoinGroup::
	call CableClub_EventScript_TryJoinLinkGroup
	compare VAR_RESULT, LINKUP_SUCCESS
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_WirelessLinkSuccessful
	compare VAR_RESULT, LINKUP_FAILED
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_ChooseLeader
	compare VAR_RESULT, LINKUP_RETRY_ROLE_ASSIGN
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_TryJoinGroup
	compare VAR_RESULT, LINKUP_FAILED_BATTLE_TOWER
	goto_if_eq BattleFrontier_BattleTowerLobby_EventScript_AbortLink
	release
	return

BattleFrontier_BattleTowerLobby_EventScript_WirelessLinkSuccessful::
	incrementgamestat GAME_STAT_ENTERED_BATTLE_TOWER
	setvar VAR_BRAVO_TRAINER_BATTLE_TOWER_ON, FALSE
	message BattleFrontier_BattleTowerLobby_Text_SaveGameBeforeShowingIn
	waitmessage
	tower_save CHALLENGE_STATUS_SAVING
	special SaveForBattleTowerLink
	waitstate
	playse SE_SAVE
	waitse
	goto BattleFrontier_BattleTowerLobby_EventScript_EnterElevator
	end

BattleFrontier_BattleTowerLobby_EventScript_RulesBoard::
	lockall
	msgbox BattleFrontier_BattleTowerLobby_Text_RulesAreListed, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_ReadRulesBoard
	end

BattleFrontier_BattleTowerLobby_EventScript_ReadRulesBoard::
	message BattleFrontier_BattleTowerLobby_Text_ReadWhichHeading
	waitmessage
	multichoice 17, 2, MULTI_BATTLE_TOWER_RULES, FALSE
	switch VAR_RESULT
	case 0, BattleFrontier_BattleTowerLobby_EventScript_RulesTower
	case 1, BattleFrontier_BattleTowerLobby_EventScript_RulesMons
	case 2, BattleFrontier_BattleTowerLobby_EventScript_RulesSalon
	case 3, BattleFrontier_BattleTowerLobby_EventScript_RulesMultiLink
	case 4, BattleFrontier_BattleTowerLobby_EventScript_ExitRules
	case MULTI_B_PRESSED, BattleFrontier_BattleTowerLobby_EventScript_ExitRules
	end

BattleFrontier_BattleTowerLobby_EventScript_RulesTower::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainTowerRules, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_ReadRulesBoard
	end

BattleFrontier_BattleTowerLobby_EventScript_RulesMons::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainMonRules, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_ReadRulesBoard
	end

BattleFrontier_BattleTowerLobby_EventScript_RulesSalon::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainSalonRules, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_ReadRulesBoard
	end

BattleFrontier_BattleTowerLobby_EventScript_RulesMultiLink::
	msgbox BattleFrontier_BattleTowerLobby_Text_ExplainMultiLinkRules, MSGBOX_DEFAULT
	goto BattleFrontier_BattleTowerLobby_EventScript_ReadRulesBoard
	end

BattleFrontier_BattleTowerLobby_EventScript_ExitRules::
	releaseall
	end

@ Unused
BattleFrontier_BattleTowerLobby_EventScript_DirectYouToBattleRoom:
    .string "我将带你到对战房间。$"

BattleFrontier_BattleTowerLobby_Text_DidntSaveBeforeQuitting:
    .string "对不起！\p上回你退出挑战时\n并没有进行保存，\l因此你的挑战无效。\p非常抱歉！$"

BattleFrontier_BattleTowerLobby_Text_CongratsBeatenSeven:
    .string "恭喜你！\n七位训练师都被你打败了！\p$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_EarnedFabulousPrize:
    .string "作为打败七位训练师的奖励，\n你会得到精美的奖品！\p$"

BattleFrontier_BattleTowerLobby_Text_ReceivedPrize:
    .string "{PLAYER}得到奖品\n{STR_VAR_1}。$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_BagFullMakeRoom:
    .string "啊，你的背包已经满了。\p请将背包整理好之后\n再来找我。$"

BattleFrontier_BattleTowerLobby_Text_ThankYouForPlaying:
    .string "感谢你的光临！\p$"

BattleFrontier_BattleTowerLobby_Text_RecordWillBeSaved:
    .string "准备保存记录，\n请稍等。$"

BattleFrontier_BattleTowerLobby_Text_WeveBeenWaitingForYou:
    .string "我们正在等你！\p$"

BattleFrontier_BattleTowerLobby_Text_ProgressWillBeSaved:
    .string "进入对战房间之前需要\n保存进度，请稍等。$"

BattleFrontier_BattleTowerLobby_Text_AboutToFace50thTrainer:
    .string "下面你将面对的是\n第五十位训练师了，\p现在开始，你每次连续打败\n七位训练师，我们会奖给你的宝可梦\l纪念品缎带。\p祝你好运！$"

BattleFrontier_BattleTowerLobby_Text_HereAreSomeRibbons:
    .string "这是连续打败七位\n强大的训练师的奖励。\p{PLAYER}得到缎带！$"

BattleFrontier_BattleTowerLobby_Text_PutRibbonOnMons:
    .string "{PLAYER}把缎带给\n挑战的宝可梦系上。$"

BattleFrontier_BattleTowerLobby_Text_DescribeFeelingsAboutBattleTower:
    .string "打扰了，能占用你一点时间吗？\p请说说你在对战塔比赛\n开始之前的想法，也可以\l谈谈赢了或输了比赛\l之后的感受。$"

BattleFrontier_BattleTowerLobby_Text_FeelWhatWhenYouBegin:
    .string "那么，你在比赛之前\n有什么想法呢？$"

BattleFrontier_BattleTowerLobby_Text_FeelWhatWhenYouveWon:
    .string "那么，你在赢了比赛之后\n有什么感受呢？$"

BattleFrontier_BattleTowerLobby_Text_FeelWhatWhenYouveLost:
    .string "能告诉我们输了比赛\n你有什么话想说吗？$"

BattleFrontier_BattleTowerLobby_Text_DontThinkMuchAboutIt:
    .string "啊，那么说你并不会多想吗？\n看来是个沉着的人啊。$"

BattleFrontier_BattleTowerLobby_Text_ChangedYourMind:
    .string "哎？你改主意了吗？\n看来你是个易变的人啊。$"

BattleFrontier_BattleTowerLobby_Text_ThatsHowYouFeel:
    .string "嗯，你是这么想的吗？\n与众不同啊。\p谢谢！$"

BattleFrontier_BattleTowerLobby_Text_WinsInRowRecorded:
    .string "连胜的次数都会\n被记录下来。\p我得努力不要被打得太惨\n以至于不敢见人！$"

BattleFrontier_BattleTowerLobby_Text_CanLeaveUntilLossOrSevenWins:
    .string "进入对战塔之后，\n除非被打败或者连胜七人，\l否则是不可以离开的。\p开始挑战之前你最好估计一下\n自己有没有挑战的实力。$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_DoubleBattleRoomConstruction:
    .string "欢迎来到对战塔\n双打对战区！\p很不幸，对战房间\n还在建设之中。\p当建筑完成后\n再来吧。$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_MultiBattleRoomConstruction:
    .string "欢迎来到对战塔\n多人对战区！\p很不幸，对战房间\n还在建设之中。\p当建筑完成后\n再来吧。$"

BattleFrontier_BattleTowerLobby_Text_LookForwardToAnotherChallenge:
    .string "希望还能在别的挑战中\n遇到你！$"

BattleFrontier_BattleTowerLobby_Text_WhichLevelMode:
    .string "对战房间有两种挑战等级，\n50级和自由级。\l你想选哪种？$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_PleaseSelectMons:
    .string "请选择要参加的\n宝可梦。$"

BattleFrontier_BattleTowerLobby_Text_OkayToSaveBeforeEntering:
    .string "进入对战房间之前需要\n进行保存，可以吗？$"

BattleFrontier_BattleTowerLobby_Text_ShowYouToBattleRoom:
    .string "现在请进入\n{STR_VAR_1}对战房间。$"

BattleFrontier_BattleTowerLobby_Text_RecordLastMatch:
    .string "要把对战塔的对战成绩\n记录在开拓区通行证上吗？$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLv50:
    .string "对不起，\p你符合条件的宝可梦不足{STR_VAR_2}只。\p必须有{STR_VAR_2}只不同的50级以下的\n宝可梦才可以参加比赛，\p同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLvOpen:
    .string "对不起，\p你符合条件的宝可梦不足{STR_VAR_2}只。\p必须有{STR_VAR_2}只不同的宝可梦\n才可以参加比赛，\p同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLv50Singles:
    .string "对不起，\p你符合条件的宝可梦不足三只。\p必须有三只不同的50级以下的\n宝可梦才可以参加比赛，\n同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLvOpenSingles:
    .string "对不起，\p你符合条件的宝可梦不足三只。\p必须有三只不同的宝可梦\n才可以参加比赛，\p同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLv50Doubles:
    .string "对不起，\p你符合条件的宝可梦不足四只。\p必须有四只不同的50级以下的\n宝可梦才可以参加比赛，\p同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLvOpenDoubles:
    .string "对不起，\p你符合条件的宝可梦不足四只。\p必须有四只不同的宝可梦\n才可以参加比赛，\p同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLv50Multis:
    .string "对不起，\p你符合条件的宝可梦不足两只。\p必须有两只不同的50级以下的\n宝可梦才可以参加比赛，\p同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

BattleFrontier_BattleTowerLobby_Text_NotEnoughValidMonsLvOpenMultis:
    .string "对不起，\p你符合条件的宝可梦不足两只。\p必须有两只不同的宝可梦\n才可以参加比赛，\p同时这些宝可梦携带的物品\n也必须各不相同。\p蛋{STR_VAR_1}不能参加。\p准备好之后再来吧。$"

BattleFrontier_BattleTowerLobby_Text_WelcomSingleBattle:
    .string "这里是检验训练师的\n天赋的地方！\p欢迎来到对战塔！\p我将领你进入\n单人对战房间。$"

BattleFrontier_BattleTowerLobby_Text_TakeSinglesChallenge:
    .string "想要挑战\n单人对战房间吗？$"

BattleFrontier_BattleTowerLobby_Text_ExplainSinglesChallenge:
    .string "对战塔的单人对战房间\n是用三只宝可梦进行\l单人对战的设施，\p对战塔里有很多\n单人对战房间，\l可以进行团体对战。\p在单人对战房间中，\n会有七位训练师等待挑战，\p如果顺利打败了七人，\n就可以获得对战点数。\p中断挑战请先保存记录\n否则将视为主动弃权。$"

BattleFrontier_BattleTowerLobby_Text_SelectThreeMons:
    .string "现在请选择参加挑战的\n三只宝可梦。$"

BattleFrontier_BattleTowerLobby_Text_WelcomeDoubleBattle:
    .string "这里是检验训练师的\n天赋的地方！\p欢迎来到对战塔！\p我将领你进入\n双打对战房间。$"

BattleFrontier_BattleTowerLobby_Text_TakeDoublesChallenge:
    .string "想要挑战\n双打对战房间吗？$"

BattleFrontier_BattleTowerLobby_Text_ExplainDoublesChallenge:
    .string "对战塔的双打对战房间\n是用四只宝可梦进行\l双打对战的设施，\p对战塔里有很多\n双打对战房间，\l可以进行团体对战。\p在双打对战房间中，\n会有七位训练师等待挑战，\p如果顺利打败了七人，\n就可以获得对战点数。\p中断挑战请先保存记录，\n否则将视为主动弃权。$"

BattleFrontier_BattleTowerLobby_Text_PleaseSelectFourMons:
    .string "现在请选择参加挑战的\n四只宝可梦。$"

BattleFrontier_BattleTowerLobby_Text_WelcomeMultiBattle:
    .string "这里是检验训练师的\n天赋的地方！\p欢迎来到对战塔！\p我将领你进入\n多人对战房间。$"

BattleFrontier_BattleTowerLobby_Text_TakeMultisChallenge:
    .string "想要挑战\n多人对战房间吗？$"

BattleFrontier_BattleTowerLobby_Text_ExplainMultisChallenge:
    .string "对战塔的多人对战房间\n是进行多人对战的设施。\p要参加多人对战，你需要在塔里\n选择一名训练师作为搭档，\l每人携带两只宝可梦进行比赛。\p塔里有一个叫做\n对战沙龙的房间，可以\l在那里找到别的训练师。\p然后你选定一起进行\n多人对战挑战的搭档。\p决定搭档后，就可以进入\n多人对战房间了。\p在多人对战房间中，\n会有七组训练师等待挑战，\p如果顺利打败七组，\n就可以获得对战点数。\p中断挑战请先保存记录，\n否则将视为主动弃权。$"

BattleFrontier_BattleTowerLobby_Text_PleaseSelectTwoMons:
    .string "现在请选择参加挑战的\n两只宝可梦。$"

BattleFrontier_BattleTowerLobby_Text_WelcomeLinkMultiBattle:
    .string "这里是检验训练师的\n天赋的地方！\p欢迎来到对战塔！\p我将领你进入\n联线多人对战房间。$"

BattleFrontier_BattleTowerLobby_Text_TakeLinkMultisChallenge:
    .string "想要挑战\n联线多人对战房间吗？$"

BattleFrontier_BattleTowerLobby_Text_ExplainLinkMultisChallenge:
    .string "对战塔的多人对战房间\n是和朋友一起进行\l多人对战的设施。\p你需要先使用无线接收器\n或GBA通信线\l与朋友连接，\p携带两只宝可梦和朋友\n组队进行挑战。\p对战塔里有很多\n多人对战房间，\p可以进行团体对战。\n在多人对战房间中，\l会有七组训练师等待\p你和你朋友的组队挑战。\n如果顺利打败七组，\p就可以获得对战点数。\n请注意这里与其他房间不同，\p你不能中断挑战。一旦挑战开始，\n就必须不间断地进行七次多人对战。$"

BattleFrontier_BattleTowerLobby_Text_PleaseSelectTwoMons2:
    .string "现在请选择参加挑战的\n两只宝可梦。$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_ChoseSameMonAsFriend:
    .string "你和你的朋友选择了\n同一种宝可梦。\p请选择与你朋友不同\n的宝可梦，确认你们选择的是同样的\l挑战等级，然后重新申请挑战。$"

BattleFrontier_BattleTowerLobby_Text_LinkMultiOnlyForTwoPlayers:
    .string "联线多人对战房间的挑战\n只对两位连接上的玩家开放。$"

BattleFrontier_BattleTowerLobby_Text_FriendAlsoSelectedMon:
    .string "你的朋友也选择了\n宝可梦{STR_VAR_1}。$"

BattleFrontier_BattleTowerLobby_Text_FriendAlsoSelectedMons:
    .string "你的朋友也选择了\n宝可梦{STR_VAR_1}和{STR_VAR_2}。$"

BattleFrontier_BattleTowerLobby_Text_FriendChoseDifferentLvlMode:
    .string "你的朋友选择了不同的\n挑战等级。$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_FriendChoseDifferentLvlModeSameMon:
    .string "你的朋友选择了不同的\n挑战等级。\p你的朋友也选择了\n宝可梦{STR_VAR_1}。$"

@ Unused
BattleFrontier_BattleTowerLobby_Text_FriendChoseDifferentLvlModeSameMons:
    .string "你的朋友选择了不同的\n挑战等级。\p你的朋友也选择了\n宝可梦{STR_VAR_1}和{STR_VAR_2}。$"

BattleFrontier_BattleTowerLobby_Text_ChooseDifferentMonsMatchLvlMode:
    .string "请选择两只与你的朋友不同的宝可梦，\n确认你们选择的是同样的挑战等级，\l然后重新申请挑战。$"

BattleFrontier_BattleTowerLobby_Text_SaveGameBeforeShowingIn:
    .string "开始挑战之前需要保存，\n请稍等。$"

BattleFrontier_BattleTowerLobby_Text_CongratsDefeatedMaiden:
    .string "恭喜！\n你打败了沙龙使女，并且\l与七位训练师的战斗中取得了全胜！$"

BattleFrontier_BattleTowerLobby_Text_AwardYouTheseBattlePoints:
    .string "为了表彰你无穷的天赋，\n这些对战点数奖给你。$"

BattleFrontier_Text_ObtainedXBattlePoints:
    .string "{PLAYER}获得{STR_VAR_1}点对战点数。$"

BattleFrontier_BattleTowerLobby_Text_RulesAreListed:
    .string "写着对战塔的规则。$"

BattleFrontier_BattleTowerLobby_Text_ReadWhichHeading:
    .string "要读哪一条？$"

BattleFrontier_BattleTowerLobby_Text_ExplainTowerRules:
    .string "对战塔中\n有四种类型的战斗——\l单人对战，双打对战，\l多人对战和联线多人对战。\p每种战斗都有不同的\n对战房间，\p请到相应的向导处\n申请参加挑战。$"

BattleFrontier_BattleTowerLobby_Text_ExplainMonRules:
    .string "根据进入的对战房间的不同，\n需要携带的宝可梦的数量\l也各不同。\p单人对战模式\n需要三只宝可梦，\p双打对战需要四只，\n而多人模式需要两只。$"

BattleFrontier_BattleTowerLobby_Text_ExplainSalonRules:
    .string "在对战沙龙里\n你可以找到一同组队挑战\l多人对战房间的训练师。\p仔细对比每个训练师的\n宝可梦和它们所会的技能，\l然后选择最适合你的搭档。\p连续打败七组训练师后\n你可以更换搭档。$"

BattleFrontier_BattleTowerLobby_Text_ExplainMultiLinkRules:
    .string "通过联线多人对战模式\n可以和朋友一起挑战。\p必须先和朋友通过\n无线接收器或\lGBA通信线进行连接，\p并在挑战申请处选好\n你要携带的宝可梦，\p这些宝可梦必须\n与你朋友的不同。\p同时，与其他模式不同，\n在这里你不可以中断挑战。$"
